
from flask import Blueprint, request, jsonify
from tool.auth.cookieCheck import cookie_jwt_required
from tool.config import config as tool_config

config = tool_config.get_config("config.toml")

settings_bp = Blueprint('settings', __name__)

@settings_bp.route("/api/settings", methods=["GET", "POST"])
@cookie_jwt_required
def user_settings_handler():
    current_user = request.user["user"]
    if request.method == "GET":
        return jsonify(config), 200
    data = request.get_json()
    # 将json转为字典格式
    tool_config.write_config("config.toml",data)

    return jsonify({"message": "设置已更新"}), 200